<html>

<head>
    <title>聊天室</title>
    <!-- 自适配手机端尺寸 -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" />
    <style>
        .line {
            display: flex;
            justify-content: center;
            margin: 1rem;
            gap: 1rem;
            flex-wrap: wrap;
        }

        .msg {
            display: flex;
            justify-content: flex-start;
            margin: 0.5rem;
            gap: 1rem;
            flex-wrap: wrap;
        }

        .content {
            display: flex;
            flex-direction: column;
            width: 400px;
            border: solid 1px;
            padding: 1rem;
            overflow-x: scroll;
            max-height: 500px;
            overflow-y: auto;
            min-height: 100px;
        }

        .name {
            width: 35px;
            text-overflow: ellipsis;
            overflow: hidden;
        }

        .time {
            color: gray;
        }

        .info {
            position: fixed;
            top: 20%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: lightgray;
            padding: 1rem;
            border-radius: 1rem;
            opacity: 0.9;
        }
    </style>
</head>

<body>
    <div class="line">
        <div>
            <div class="line">
                <div>用户id</div>
                <input name="userid" placeholder="请输入内容" value="" />
            </div>
            <div class="line">
                <button>登录</button>
                <button>重置</button>
            </div>
        </div>
    </div>

    <!-- <div class="info">
        提示消息
    </div> -->
    <script>

        let serverUrl = 'http://localhost:9090/chat.html'

        let l = localStorage
        let elUserid = document.getElementsByName('userid').item(0)
        let btnLogin = document.getElementsByTagName('button').item(0)
        let btnReset = document.getElementsByTagName('button').item(1)

        function login() {
            let userId = elUserid.value
            if (userId) {
                l['userId'] = userId
                location.href = 'chat.html?userId=' + userId
            } else {
                alert('请输入用户id')
            }
        }

        function reset() {
            elUserid.value = ''
            l['userId'] = ''
        }

        document.body.onload = async () => {
            btnLogin.onclick = login
            btnReset.onclick = reset
            elUserid.value = localStorage['userId'] || elUserid.value
        }



    </script>

</body>

</html>